package com.codeduck.bean.entity;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

/**
 * 通过实现接口 InitializingBean, DisposableBean来实现 bean 的初始化与销毁方法
 *
 * 向 Spring 注册 BeanLifeCycleII : {@link com.codeduck.bean.config.BeanLifeCycleConfigII}
 *
 * @author: <a href="mailto:codeduck@163.com">Codeduck</a>
 * @createDate: 2021-12-23
 */
@Slf4j
public class BeanLifeCycleII implements InitializingBean, DisposableBean {

    private String name;

    public BeanLifeCycleII() {
        log.warn("bean的构造方法调用完毕");
    }

    public void setName() {
        this.name = "name";
        log.warn("bean#setName 方法调用完毕");
    }

    public void init() {
        log.warn("@Bean#initMethod 方法调用完毕");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.warn("InitializingBean#afterPropertiesSet 方法调用完毕");
    }

    @Override
    public void destroy() throws Exception {
        log.warn("DisposableBean#destroy 方法调用完毕");
    }
}
